{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="test-table-reload-btn">
                <div class="layui-inline">
                    <select name="type" id="type" lay-filter="">
                        <option value="">请选择类型</option>
                        <option value="money">充值</option>
                        <option value="seat">坐席</option>
                        <option value="servicetime">服务续费</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="keywords" id="keywords" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>
            <script type="text/html" id="op">
                {{#  if( d.state == 0){ }}
                        <a class="layui-btn layui-btn-xs" lay-event="setstate" title="坐席确认">技术确认</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form'], function () {

        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table,util = layui.util;
        table.render({
            elem: '#tbList',
            url: "{:url('getMessage')}",
            cellMinWidth: 80,
            cols: [[
                {field: 'id', fixed: 'left',width:60, title: 'id', sort: false},
                {field: 'co',fixed:'left',title:'公司名称',sort: true},
                {field: 'title',title:'操作内容',sort: true},
                {field: 'username',title:'操作人',sort: true},
                {field: 'kf_name',title:'客服',sort: true,width:80},
                {field: 'created_time', title: '操作时间', templet: function (d) {return util.toDateString(d.created_time*1000, "yyyy-MM-dd HH:mm:ss");}},
                {fixed: 'right', title: '操作', toolbar: '#op',width:80}
            ]],
            page: true,
            limit:15,
            done: function(res, curr, count){
                var data=res.data
                for(var i in data){

                }
            }
        });

        // 监听工具条
        table.on('tool(tbList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除', {icon: 3, title: '提示'}, function (index) {
                    // obj.del();
                    // layer.close(index);
                    $.post("{:url('del')}", {id: data['id']}, function (result) {
                        if (result['code'] == 0) {
                            layer.msg(result['msg'], {icon: 1, time: 2000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                });
            }else if (obj.event === 'setstate') {
                $.post("{:url('setstate')}", {id: data['id'], state:1}, function (result) {
                    if (result['code'] == 0) {
                        layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(result['msg'], {icon: 3, time: 3000});
                    }
                });
            }
        });


        //操作
        var $ = layui.$, active = {
            reload: function(){
                var type=$('#type').val();
                var keywords=$('#keywords').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        type: type
                        ,keywords: keywords
                    }
                });

            }
        };

        $('.layui-card-header .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}